#include "XSystem/XCore.h"
#include "GPopup.h"

// Initialize the window
GPopup::GPopup(XResourcesManager *data) : XWindow(data)
{
	// Default values
    x_positionX = 230;
    x_positionY = 230;
    x_width = 340;
    x_height = 140;
	x_view.Move(-x_positionX, -x_positionY);

	x_windowBackground.SetImage(x_data->GetImage("gui/popup.png"));

	x_widgets["labeltext"] = new XLabel(data, 24, 40, "");

	x_widgets["buttonclose"] = new XPushButton(data, 50, 16, 100, 80);
}

// Draws the window
void GPopup::Draw()
{
    if (x_visible)
    {
		x_widgets["labeltext"]->SetText(x_data->GetString("popup-text"), true);
        XWindow::Draw();
    }
}

// Refresh the window
void GPopup::CheckState(const sf::Input &input)
{
	// Check the state of the widgets
    XWindow::CheckState(input);

	if (x_widgets["buttonclose"]->state() == XG_ST_LBUTTON_RELEASED)
		x_visible = false;
}
